package com.epidemic.project.system.wuzi.controller;

import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.epidemic.project.system.wuzi.domain.SysWuZi;
import com.epidemic.project.system.wuzi.service.ISysWuZiService;
import com.epidemic.framework.web.controller.BaseController;
import org.springframework.stereotype.Controller;
import com.epidemic.framework.web.domain.AjaxResult;
import com.epidemic.common.utils.poi.ExcelUtil;
import com.epidemic.framework.web.page.TableDataInfo;

/**
 * 物资申请Controller
 *
 * @author sys
 * @date 2023-02-01
 */
@Controller
@RequestMapping("/system/wuzi")
public class SysWuZiController extends BaseController {
    private String prefix = "system/wuzi";

    @Autowired
    private ISysWuZiService sysWuZiService;

    @RequiresPermissions("system:wuzi:view")
    @GetMapping()
    public String wuzi() {
        return prefix + "/wuzi";
    }

    /**
     * 查询物资申请列表
     */
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(SysWuZi sysWuZi) {
        startPage();
        List<SysWuZi> list = sysWuZiService.selectSysWuZiList(sysWuZi);
        return getDataTable(list);
    }

    /**
     * 导出物资申请列表
     */
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(SysWuZi sysWuZi) {
        List<SysWuZi> list = sysWuZiService.selectSysWuZiList(sysWuZi);
        ExcelUtil<SysWuZi> util = new ExcelUtil<SysWuZi>(SysWuZi.class);
        return util.exportExcel(list, "wuzi");
    }

    /**
     * 新增物资申请
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存物资申请
     */
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(SysWuZi sysWuZi) {
        return toAjax(sysWuZiService.insertSysWuZi(sysWuZi));
    }

    /**
     * 修改物资申请
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap) {
        SysWuZi sysWuZi = sysWuZiService.selectSysWuZiById(id);
        mmap.put("sysWuZi", sysWuZi);
        return prefix + "/edit";
    }

    /**
     * 修改保存物资申请
     */
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(SysWuZi sysWuZi) {
        return toAjax(sysWuZiService.updateSysWuZi(sysWuZi));
    }

    /**
     * 删除物资申请
     */
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(sysWuZiService.deleteSysWuZiByIds(ids));
    }
}
